package com.tanhua.task;

import com.tanhua.api.db.UserInfoApi;
import com.tanhua.domain.db.UserInfo;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;

import java.util.Timer;
import java.util.TimerTask;

/*定时任务*/
@Component
@Scope("prototype")
public class Task {
    @Reference
    private UserInfoApi userInfoApi;
    @Autowired
    private StringRedisTemplate stringRedisTemplate;
    public void timer(Long userId,Long time) {
        Timer timer = new Timer();
        timer.schedule(new TimerTask() {
            @Override
            public void run() {
                System.out.println(userId);
                UserInfo userInfo = userInfoApi.findUserInfo(userId);
                if (userInfo.getUserStatus().equals("2")) {
                    userInfoApi.unfreezeUser(userId.toString());
                    stringRedisTemplate.delete("freeZing_" + userId);
                }
                return;
            }
        },time);
    }
}
